<?php
/**
 * @author: wangxiwen
 * @date: 2021/1/12 2:12 下午
 */

namespace App\Http\Services;
use App\Http\Model\RoomUser;
use App\Http\Model\RoomHostMicro;
use App\Http\Model\RoomMicro;


class AnnualCeremonyServices extends CommonServices
{
    protected $roomUser;
    protected $roomHostMicro;
    protected $roomMicro;

    public function __construct()
    {
        parent::__construct();

        $this->roomUser = new RoomUser();
        $this->roomHostMicro = new RoomHostMicro();
        $this->roomMicro = new RoomMicro();
    }

    /**
     * 获取用户是否在直播
     * @param array $userIds
     * @return array
     */
    public function getUserRoom($userIds = [])
    {
        $data = [];
        foreach($userIds as $userId) {
            $roomId = $this->roomUser->get_user_cur_room($userId);
            if($roomId == null) {
                $data[$userId] = 0;
                continue;
            }
            $hostId = $this->roomHostMicro->get_user_id($roomId);
            if($hostId == null || $userId != $hostId) {
                $data[$userId] = 0;
            }
            $data[$userId] = $roomId;
        }
        return $data;
    }

    /**
     * 获取房间主持人
     * @param $roomId
     * @return bool
     */
    public function getRoomHost($roomId)
    {
        $hostId = $this->roomHostMicro->get_user_id($roomId);
        if($hostId > 0 === false) {
            return 0;
        }
        return $hostId;
    }

    /**
     * 获取房间麦上的用户
     * @param $roomId
     */
    public function getRoomMicros($roomId, $roomType)
    {
        $users = $this->roomMicro->get_micros($roomId, $roomType);
        $data = [];
        foreach($users as $user) {
            if($user['user_id'] == null) {
                continue;
            }
            $data[] = $user['user_id'];
        }
        return $data;
    }


}
